var appPath = getAppPath();

$(function(){
	// 大分类
	$("#editTopicType").combobox({
		url:appPath+'/itbTg/getTypeForCombo.action?&blkFlg=0',
		valueField:'type_id',
		textField:'type_name',
		onSelect:function(selRecd){
			$("#editTopicType2").combobox("clear");
			$("#editTopicType3").combobox("clear");
			$("#editTopicType2").combobox("loadData",{});
			$("#editTopicType3").combobox("loadData",{});
			
			var parentId=selRecd.type_id;
			$("#editCurType").val(selRecd.type_id);
			
			if(Number(parentId)>0){
				// 中分类
				$("#editTopicType2").combobox({
					url:appPath+'/itbTg/getTypeForCombo.action?parent='+parentId+'&blkFlg=1',
					valueField:'type_id',
					textField:'type_name',
					onSelect:function(selRecd2){
						$("#editTopicType3").combobox("clear");
						$("#editTopicType3").combobox("loadData",{});
						
						var parentId2=selRecd2.type_id;
						$("#editCurType").val(selRecd2.type_id);
						
						if(Number(parentId2)>0){
							// 小分类
							$("#editTopicType3").combobox({
								url:appPath+'/itbTg/getTypeForCombo.action?parent='+parentId2+'&blkFlg=1',
								valueField:'type_id',
								textField:'type_name',
								onSelect:function(selRecd3){
									$("#editCurType").val(selRecd3.type_id);
								}
							});
						}
					}
				});
			}
		}
	});
	
	initJspGrid();
});

// 样版列表初始化
function initJspGrid(){
	$('#topicGrid').datagrid({
	    url:appPath + "/itbCom/getTopicInfoPg.action",
	    height:'full',
	    //remoteSort:false,
	    striped:true,
	    fitColumns:true,
	    nowrap: false,// 换行
	    queryParams: getQueryParam(),
	    singleSelect:false,
	    // If set to true, clicking a checkbox will always select the row. 
	    // If false, selecting a row will not check the checkbox.
	    selectOnCheck:true,
	    // If true, the checkbox is checked/unchecked when the user clicks on a row. 
	    // If false, the checkbox is only checked/unchecked when the user clicks exactly on the checkbox.
	    checkOnSelect:true,
	    frozenColumns:[[
	        {field:'ck',checkbox:'true',width:10,align:'center',sortable:false}
	    ]],
	    columns:[[
  	        {field:'thumb',title:'缩略图',width:80,align:'center',sortable:false,
	        	formatter:function(thumb, rowData, rowIndex){
	        		var retUrl = '';
	        		if (rowData.thumb) {
	        			retUrl = '<a href="' + rowData.thumb + '" target="_blank">'
	        				+ '<div style="display:table;text-align:center;height:110px;width:100%">'
	        				+ '<span style="display:table-cell;vertical-align:middle">'
	        				+ '<img src="' + rowData.thumb.replace('oss-cn-hangzhou.aliyuncs.com','img-cn-hangzhou.aliyuncs.com') + '@128h_128w_1l.png'
	        				+ '" style="display:inline;max-height:100px;max-width:100px"><span></div></a>';
	        		}
	        		return retUrl;
	        	}},
			{field:'edit',title:'编辑',width:35,align:'center',sortable:false,
				formatter:function(value,rowData,rowIndex){
					//if(Number(rowData.publish||'0')==1) return "N/A";
					var ret = "<a href='javascript:void(0)'><img width='12px' height='12px' style='border:0px' src='"+appPath+"/js/lib/jquery-easyui/themes/icons/pencil.png' title='编辑' ";
					ret += " onClick='editTopic("+rowData.st_id+")'/></a>";
					return ret;
				}
			},
	        {field:'st_id',title:'专题ID',width:40,align:'center',sortable:false},
	        {field:'top_type',title:'大分类',width:40,align:'center',sortable:false,
		    	  formatter:function(type, rowData, rowIndex){
		    		  var tp = '<span style="color:red">未知</span>';
		    		  switch(Number(type)){
		    		  	case 1: tp = '单页';break;
		    		  	case 2: tp = '多页';break;
		    		  	case 3: tp = 'PPT';break;
		    		  	case 4: tp = '印品';break;
		    		  	case 6: tp = '社交媒体';break;
		    		  	case 7: tp = '电商';break;
		    		  	case 8: tp = '微商';break;
		    		  	case 1010: tp='Logo商品';break;
		    		  	case 1011: tp='营销商品';break;
		    		  }
		    		  return tp;
		    	  }
		      },
		    {field:'type_name',title:'当前分类',width:40,align:'center',sortable:false,
		    	  formatter:function(typeNm, rowData, rowIndex){
		    		  return typeNm;
		    	  }
		      },
	        {field:'use',title:'用途',width:30,align:'center',sortable:false,
		    	  formatter:function(use, rowData, rowIndex){
		    		  var u = '<span style="color:red">未知</span>';
		    		  switch(Number(use)){
		    		  	case 1: u = '<span style="color:red">热门</span>';break;
		    		  	case 2: u = '<span style="color:blue">专题</span>';break;
		    		  }
		    		  return u;
		    	  }
		      },
	        {field:'title',title:'专题名称',width:100,align:'left',sortable:false},
	        {field:'desc',title:'简介',width:100,align:'left',sortable:false,
	        	formatter:function(desc, rowData, rowIdx){
	        		var ret = rowData.desc;
	        		if(ret && ret.length>10){
	        			return ret.substr(0,10)+'...';
	        		}
	        		return ret;
	        	}
	        },
	        {field:'order',title:'排序',width:20,align:'center',sortable:false,
		    	  formatter:function(value, rowData, rowIndex){
		    		  if(!rowData.st_id) return "";
		    		  return "<a href='javascript:void(0)' onClick='editOrder("+rowData.st_id+","+rowData.order+")'>"+rowData.order+"</a>";
		    	  }
		    },
	        {field:'publish',title:'发布状态',width:35,align:'center',sortable:false,
	        	formatter:function(publish, rowData, rowIndex){
	        		if (Number(publish) == 1) return '<font color="green">已发布</font>';
	        		return '<font color="red">未发布</font>';
	        	}
	        },
	        {field:'design', title:'专题内容', width:40, align:'center',sortable:false,
	        	formatter:function(value,rowData,rowIndex){
	        		return "<a href='javascript:void(0)' onclick='design(\""+rowData.type_name+"\","+rowData.st_id+","+rowData.type+")'>点击设置</a>";
	        	}
	        },
	        {field:'create_time',title:'创建时间',width:50,align:'center',sortable:false},
	        {field:'update_time',title:'更新时间',width:50,align:'center',sortable:false}
	    ]],
	    hideColumn:['user_type'],
	    //view: imgView,// 自定义View
	    pagination:true,
		rownumbers:true,
		toolbar:[{
				text:'<i class="fa fa-calendar-plus-o" style="color:green;font-size:15px"></i>添加专题',
//				iconCls:'icon-add',
				handler:function(){
					addTopic();
				}
			},
			'-',
			{
				text:'<i class="fa fa-check-circle" style="color:green;font-size:15px"></i>发布专题',
//				iconCls:'icon-ok',
				handler:function(){
					doPublish();
				}
			},
			'-',
			{
				text:'<i class="fa fa-repeat" style="font-size:15px"></i>取消发布',
//				iconCls:'icon-cancel',
				handler:function(){
					cancelPublish();
				}
			},
			'-',
			{
				text:'<i class="fa fa-trash" style="color:red;font-size:15px"></i>删除专题',
//				iconCls:'icon-cancel',
				handler:function(){
					delTopic();
				}
			}
//			'-',
//			{
//				text:'<span style="color:red">清除官网缓存</span>',
//				iconCls:'icon-reload',
//				handler:function(){
//					$.messager.confirm("确认",
//						"<span style='color:blue'>清除[API/HOME]服务器缓存</span><br/><span style='color:blue'>包括APP首页数据/官网首页数据</span><br/><span style='color:red'>是否确认清除缓存？</span>",
//						function(r){
//					        if (r) {
//								var url = getHomeServer()+"/clearStaticize";
//								$.get(url,function(ret){
//									if(ret && ret.ok){
//										$.messager.alert('提示信息','缓存清除成功','info');
//									}else{
//										$.messager.alert('提示信息','缓存清除失败','info');
//									}
//								});
//					        }
//						}
//					);
//				}
//			},
//			'-',
//			'-',
//			{
//				text:'<span style="color:red">建立缓存</span>',
//				iconCls:'icon-reload',
//				handler:function(){
//					$.messager.confirm("确认",
//							"<span style='color:red'>是否建立缓存</span>",
//							function(r){
//						if (r) {
//							$.loading(true);
////							var url = getHomeServer()+"/clearStaticize";192.168.31.252
//							var url = "http://192.168.31.252:3000/v5/api4back/querySearchCacheStatus_v1_1";
//							$.get(url,function(ret){
//								var info=ret;
//								if(info.success == 1){	
//									var timeSt = info.data.buildCacheStart;//开始时间
//									var timeEn = info.data.buildCacheEnd;//结束时间
//									var dura = info.data.buildDuration;//持续时间
//									if(timeSt==null && timeEn==null){
//										var url2 = "http://192.168.31.252:3000/v5/api4back/querySearchCacheStatus_v1_1";
//										$.get(url,function(ret){
//											if(ret.success==1){
//												$.loading(false);
//												$.messager.alert('提示信息','准备开始建缓存....','info');
//											}
//										});
//										
//									}else if(timeSt && timeEn==null){
//										$.loading(false);
//										$.messager.alert('提示信息','还在建缓存中...，请稍等','info');
//									}else if(timeSt && timeEn==null && dura>=700){
//										$.loading(false);
//										$.messager.alert('提示信息','可能异常了 联系下管理员','info');
//									}else if(timeSt && timeEn){
//										var url2 = "http://192.168.31.252:3000/v5/api4back/switchBuildSearchDB_v1_1";
//										$.get(url,function(ret){
//											if(ret.success==1){
//												$.loading(false);
//												$.messager.alert('提示信息','缓存建立完成','info');
//											}
//										});
//									}
//									
//								}else{
//									$.loading(false);
//									$.messager.alert('提示信息','出错，联系管理员','info');
//								}
//							});
//						}
//					}
//					);
//				}
//			},
//			'-'
		]
	});
}

//展示专题下---设计模板列表
function design(title,id,type){
	$("#st_id").val(id);
	$("#stType").val(type);
	$("#stId").html(id);
	$("#stTitle").html(title);
	$('#tDesignDlg').window({
		title:'热门专题:模版列表',
		iconCls:'icon-add',
		modal: true,
		shadow: true,
		collapsible:false,
		minimizable:false,
		maximizable:false
	});
	$('#tDesignDlg').window('open');
	$('#tDesignDlg').window('move',{top:20,left:20});
	initDesignGrid();
}

//function initUploader(){
//	var url = "http://upload.itbour.com/upload/user?device=101&user_type=0&user_id="+(g_userId||0);
//    var option = {};
//    option.id = 'selImgFile';
//    option.url = url;
//    option.callback = function(res){
//    	$("#topicImg").html('');
//    	if(!res.success){
//    		alert(res.msg);
//            return;
//    	}
//    	if(res && res.data && res.data.url){
//    		var showImg = '';
//			if(res.data.url && res.data.url.length>0) {
//				showImg = res.data.url.replace('oss-cn-hangzhou.aliyuncs.com','img-cn-hangzhou.aliyuncs.com')
//					+'@200h_200w_1l.png';
//			}
//			var imgHtml = '<img src="'+showImg+'" style="display:inline;max-height:100px;max-width:200px">';
//			$("#topicImg").append(imgHtml).val(res.data.url||'');
//    	}
//    }
//    option.imgExts = ['jpg','jpeg','png'];
//    //option.bindInputFileName ='fileNameInput';
//    var uploader = new AjaxUploadEx(option);
//}

function addTopic(){
	$("#editTable").show();
	$('#editForm').form('clear');
	$("#topicImg").html('').val('');
	
	$("#trForNew").show();
	$("#trForEdit").hide();
	$("#editCurType").val(0);
	$("#editTopicType").combobox('select',1);
	//$("#editTopicType").combobox('select',1).combobox('enable');
	//$("#editTopicType2").combobox('enable');
	//$("#editTopicType3").combobox('enable');
	
	$("#editTopicUse").combobox('select',2).combobox('enable');
	
	$("#editBtn").show();
	$('#editDlg').window({
		title:'新建专题',
		iconCls:'icon-add',
		modal: true,
		shadow: true,
		collapsible:false,
		minimizable:false,
		maximizable:false
	});
	
	cancelPostData();// 上传图片清除 uploader = null
	initOSS();
	$('#editDlg').window('move',{top:20,left:20});
	$('#editDlg').window('open');
}

function editTopic(stId){
	$("#editTable").show();
	$('#editForm').form('clear');
	$("#topicImg").html('').val('');
	
	$("#trForNew").hide();
	$("#trForEdit").show();
	$("#editCurType").val(0);
	$("#showTypeForEdit").html('');
	
	$("#editStId").val(stId);
	var url = appPath + "/itbCom/getTopicInfoLst.action?st_id="+ stId;
	$.get(url,function(ret){
		if (ret && ret.length>0){
			var info = ret[0];
			var topType = Number(info.top_type||0);
			var pType = Number(info.parent_type||0);
			var type = Number(info.type||0);
			
			$("#editTopicTitle").val(info.title||'');
			$("#editTopicDesc").val(info.desc||'');
			$("#editTopicUse").combobox('select',info.use||2).combobox('disable');
			
			//$("#editTopicType").combobox('disable');
			$("#editCurType").val(type);
			if(topType>0) {
				var show = '';
				switch(Number(topType)){
					case 1: show = '单页';break;
					case 2: show = '多页';break;
					case 3: show = 'PPT';break;
					case 4: show = '印品';break;
					case 6: show = '社交媒体';break;
	    		  	case 7: show = '电商';break;
	    		  	case 8: show = '微商';break;
	    		  	case 1010: show='Logo商品';break;
	    		  	case 1011: show='营销商品';break;
				}
				if(pType>0) {// 存在中/小分类
					if(pType==topType){// 仅到中分类
						show += '/'+info.type_name;
					}else{// 小分类
						show += '/('+pType+')/'+info.type_name;
					}
				}
				$("#showTypeForEdit").html(show);
			}
			
			var showImg = '';
			if(info.thumb && info.thumb.length>0) {
				showImg = info.thumb.replace('oss-cn-hangzhou.aliyuncs.com','img-cn-hangzhou.aliyuncs.com')
					+'@200h_200w_1l.png';
			}
			var imgHtml = '<img src="'+showImg+'" style="display:inline;max-height:100px;max-width:200px">';
			$("#topicImg").append(imgHtml).val(info.thumb||'');
		}
	});
	
	$("#editBtn").show();
	$('#editDlg').window({
		title:'编辑专题',
		iconCls:'icon-edit',
		modal: true,
		shadow: true,
		collapsible:false,
		minimizable:false,
		maximizable:false
	});
	
	cancelPostData();// 上传图片清除 uploader = null
	initOSS();
	$('#editDlg').window('move',{top:20,left:20});
	$('#editDlg').window('open');
}

function cancelEdit(){
	$('#editDlg').window('close');
}

function doEdit(){
	var stId = $("#editStId").val();
	//var type = $("#editTopicType").combobox('getValue');
	//var type2 = $("#editTopicType2").combobox('getValue');
	//var type3 = $("#editTopicType3").combobox('getValue');
	var curType = $("#editCurType").val();
	var use = $("#editTopicUse").combobox('getValue');
	var title = $("#editTopicTitle").val();
	var desc = $("#editTopicDesc").val();
	var imgUrl = $("#topicImg").val();
	
	if(Number(curType||0)<=0){
		return $.messager.alert('提示信息','请选择专题分类','info');
	}
	if(title && title.length>0) {
		var url = appPath+"/itbComWeb/addTopic.action"
		var sendData = {
			"topicInfo.st_id": stId||"",
			"topicInfo.type": Number(curType),
			"topicInfo.use": Number(use || "2"),
			"topicInfo.title": title || "",
			"topicInfo.desc": desc || "",
			"topicInfo.thumb":imgUrl||""
		};
	    $.post(url, sendData, function(data){  
			if (data == "ok") { 
				$.messager.alert('提示信息','提交成功','info');
				$('#editDlg').window('close');
				doQuery();
	        } else {
	        	$.messager.alert('提示信息','提交失败','info');
	        }
	    });
	    
	}else{
		$.messager.alert('提示信息','请输入专题名称','info');
	}
	
}

function delTopic(){
	var selectItem=$("#topicGrid").datagrid("getChecked");
	if(!selectItem || selectItem.length == 0){
		$.messager.alert('提示信息','请选择专题！','warning');
		return;
	}
	for(var i=0; i<selectItem.length; i++){
		if(Number(selectItem[i].publish||'0')==1){
			$.messager.alert('提示信息','不能删除已发布专题！','warning');
			return;
		}
	}
	
	$.messager.confirm("确认",
		"是否确认[删除]所选专题？<br/><span style='color:red'>*对应的[专题/模版关联信息]将一并删除!</span>",
		function(r){
	        if (r) { 
				var ids = "";
				$.each(selectItem, function(index, item){
					ids = ids + item.st_id + ",";
				});
				var url = appPath+"/itbComWeb/delTopic.action?ids="+ids;
				$.post(url,function(data){
					if(data=="ok"){
						$.messager.alert('提示信息','删除成功','info');
						doQuery();
					}else{
						$.messager.alert('提示信息','删除失败','info');
					}
				});
	        }
		}
	);
}

// 发布专题
function doPublish(){
	var selectTopic=$("#topicGrid").datagrid("getChecked");
	if(!selectTopic || selectTopic.length == 0){
		$.messager.alert('提示信息','请选择未发布专题进行处理！','warning');
		return;
	}else if(selectTopic.length>1){
		$.messager.alert('提示信息','请选择单个专题进行处理！','warning');
		return;
	}
	
	var ids = "";
	var doFlg = false;
	$.each(selectTopic, function(index, item){
		if(item.publish != 1 && item.publish != '1'){
			doFlg = true;
			ids = ids + item.st_id + ",";
		}
	});
	
	if(!doFlg){
		$.messager.alert('提示信息','请选择未发布专题进行处理！','warning');
		return;
	}
	
	$.messager.confirm("确认",
		"是否确认[发布]专题？<br/><span style='color:red'>*请确保已经过认真检查!</span>",
		function (r) {
	        if (r) {
	        	var url = appPath+"/itbComWeb/doTopicPublish.action?ids="+ids;
	        	$.post(url,function(data){
	        		if(data=="ok"){
	        			$.messager.alert('提示信息','专题发布成功！','info');
	        			doQuery();
	        		} else if (data=="ng"){
	        			$.messager.alert('提示信息','NG!','warning');
	        		}
	        	});
	        }
		}
	);
}
// 取消发布专题
function cancelPublish(){
	var selectTopic=$("#topicGrid").datagrid("getChecked");
	if(!selectTopic || selectTopic.length == 0){
		$.messager.alert('提示信息','请选择已发布专题进行处理！','warning');
		return;
	}
	
	var ids = "";
	var doFlg = false;
	$.each(selectTopic, function(index, item){
		if(item.publish == 1 || item.publish == '1'){
			doFlg = true;
			ids = ids + item.st_id + ",";
		}
	});
	
	if(!doFlg){
		$.messager.alert('提示信息','请选择已发布专题进行处理！','warning');
		return;
	}
	
	$.messager.confirm("确认", "是否确认[取消]已发布专题？", function (r) {
		if(r){
			var url = appPath+"/itbComWeb/cancelTopicPublish.action?ids="+ids;
			$.post(url,function(data){
				if(data=="ok"){
					$.messager.alert('提示信息','专题已取消发布！','info');
					doQuery();
				}
			});
		}
	});
}

/** 显示顺序*/
function editOrder(stId, order){
	$("#orderStId").val(stId);
	$("#order").val(order);
	$("#orderBtn").show();
	$('#orderDlg').window({
		title:'显示顺序设定',
		iconCls:'icon-edit',
		modal: true,
		shadow: true,
		collapsible:false,
		minimizable:false,
		maximizable:false
	});
	
	$('#orderDlg').window('move',{top:20,left:20});
	$('#orderDlg').window('open');
}
/**修改显示顺序*/
function doUpdOrder(){
	var stId = $("#orderStId").val();
	var order = $("#order").val();
	if(!order || order.length == 0 || Number(order)>999 || Number(order)<=0){
		$.messager.alert('提示信息','有效数值范围为：1～999','warning');
		return;
	}
	var url = appPath+"/itbComWeb/updTopicOrder.action?stId="+stId+"&order="+order;
	$.post(url,function(data){
		if(data=="ok"){
			$.messager.alert('提示信息','显示顺序已更新！','info',function(){
				doQuery();
				$('#orderDlg').window('close');
			});
		}else {
			$.messager.alert('提示信息','显示顺序更新失败！','warning');
		}
	});
}

/** 结束显示顺序编辑*/
function cancelUpdOrder(){
	$('#orderDlg').window('close');
}

/**获取请求信息*/
function getQueryParam(){
	var queryObject = {};
	
	var findTopicTypeL = $("#queryTopicType").combobox('getValue');
	var findTopicUse = $("#queryTopicUse").combobox('getValue');
	var findPubFlg = $("#queryPublish").combobox('getValue');
	var findTopicTitle = $("#queryTopicTitle").val();
	
	if(findTopicTypeL && Number(findTopicTypeL||'0')>0) queryObject.findTopicTypeL = findTopicTypeL;// 类型
	if(findTopicUse && Number(findTopicUse||'0')>0) queryObject.findTopicUse = findTopicUse;// 用途
	if(findPubFlg && Number(findPubFlg||'-1')>=0) queryObject.findPubFlg = findPubFlg;// 发布标记
	if(findTopicTitle && findTopicTitle.length>0) queryObject.findTopicTitle = findTopicTitle;// 名称
	
	return queryObject;
}

/** 查询数据*/
function doQuery(){
	$("#topicGrid").datagrid('unselectAll');
	$("#topicGrid").datagrid('load', getQueryParam());
}

/**查询活动商品*/
function doQuery2(startFlg){
	$("#tDesignGrid").datagrid('unselectAll');
	if(startFlg==1){
		$("#tDesignGrid").datagrid('load', getQueryParam());
	} else {
		$("#tDesignGrid").datagrid('reload', getQueryParam());
	}
}

function fmtCreateTime(value, rowData, rowIndex){
	if(!value)return "";
	var s = new Date(value);
	return rowData.create_time=$.DateUtil.format(s,'yyyy/MM/dd hh:mm:ss');
}

//加载专题下设计模板列表
function initDesignGrid(){
	var stId=$("#st_id").val();
	var type = $("#stType").val();//获取类型 type=3为ppt
	$('#tDesignGrid').datagrid({
	    url:appPath + "/itbCom/getTopicDesignInfo.action?stId="+stId+"&type="+type,
	    height:'full',
	    striped:true,
	    fitColumns:true,
	    nowrap: false,// 换行
	    queryParams: getQueryParam(),
	    singleSelect:false,
	    selectOnCheck:true,
	    checkOnSelect:true,
	    frozenColumns:[[
	        {field:'ck',checkbox:'true',width:10,align:'center',sortable:false}
	    ]],
	    columns:[[
  	        {field:'thumb',title:'缩略图',width:70,align:'center',sortable:false,
	        	formatter:function(thumb, rowData, rowIndex){
	        		var retUrl = '';
	        		if (rowData.thumb) {
	        			retUrl = '<a href="' + rowData.thumb + '" target="_blank">'
	        				+ '<div style="display:table;text-align:center;height:120px;width:100%">'
	        				+ '<span style="display:table-cell;vertical-align:middle">'
//	        				+ '<img src="' + rowData.thumb.replace('oss-cn-hangzhou.aliyuncs.com','img-cn-hangzhou.aliyuncs.com') + '@110h_128w_1l.png'
	        				+ '<img src="'+thumb+'?x-oss-process=image/resize,m_lfit,h_100,w_125'
	        				+ '" style="display:inline;max-height:100px;max-width:125px"></span></div></a>';
	        		}
	        		return retUrl;
	        	}
  	        },
	        {field:'design_id',title:'模版ID',width:35,align:'center',sortable:false,
		    	formatter:function(id, rowData, rowIndex){
		    		var map_id = rowData.map_id;
		    		var show = '<span style="color:red">'+id+'</span>';
		    		if(map_id){
			    		var show = '<span style="color:red">'+id+'</span>'+
			    		  	'</br>'+
			    		  	'<span style="color:green">'+rowData.map_id+'</span>';
		    		}
		    		return show;
		    	}
		    },
	        {field:'size',title:'尺寸(W*H)',width:55,align:'center',sortable:false,
		    	formatter:function(value, rowData, rowIndex){
		    		return ''+(rowData.width||'N/A')+
		    			'<span style="color:green">*</span>'+
		    			(rowData.height||'N/A')+'';
		    	}
		    },
		    {field:'top_type',title:'主分类',width:35,align:'center',sortable:false,
		    	formatter:function(value, rowData, rowIndex){
		    		var tn = getTopTypeNm(value);
		    		if(!tn || tn.length==0) {
		    			tn = '<span style="color:red">未知</span>';
		    		}
		    		return tn;
		    	}
		    },
	        {field:'type_name',title:'子分类',width:40,align:'center',sortable:false,
		    	formatter:function(value, rowData, rowIndex){
		    		return rowData.type_name || '<span style="color:red">未分类</span>';
		    	}
		    },
		    {field:'user_id',title:'设计师',width:50,align:'center',sortable:false,
		    	formatter:function(value, rowData, rowIndex){
		    		return rowData.nickname || rowData.user_name || rowData.user_id || '<span style="color:red">未知</span>';
		    	}
		    },
		    {field:'order',title:'顺序',width:35,align:'center',sortable:false,
		    	  formatter:function(value, rowData, rowIndex){
		    		  if(!rowData.design_id) return "";
		    		  return "<a href='javascript:void(0)' onClick='editTorder("+rowData.design_id+","+rowData.order+")'>"+rowData.order+"</a>";
		    	  }
		    },
		    {field:'item_id',title:'关联商品',width:40,align:'center',sortable:false,
		    	formatter:function(value, rowData, rowIndex){
		    		var topType = Number(rowData.top_type||'0');
		    		if(topType!=4 && topType!=1010 && topType!=1011) {
		    			return '<span style="color:red">N/A</span>';
		    		}
		    		if(Number(value||'0')==0) {
		    			return '<span style="color:blue">未关联</span>';
		    		}
		    		return value;
		    	}
		    },
	        {field:'design_name',title:'模版名称',width:85,align:'left',sortable:false},
		    {field:'vip',title:'VIP',width:30,align:'center',sortable:false,
		    	  formatter:function(value, rowData, rowIndex){
		    		  var show = "<span style='color:green;'>普通模板</span>";
		    		  if(Number(value||'0')==10) show="<span style='color:red;'>VIP模版</span>";
		    		  return show;
		    	  }
		    },
	        {field:'publish',title:'发布状态',width:40,align:'center',sortable:false,
	        	formatter:function(publish, rowData, rowIndex){
	        		if (Number(publish) == 1) return '<span style="color:green">已发布</span>';
	        		return '<span style="color:red">未发布</span>';
	        	}
		    },
	        {field:'create_time',title:'创建时间',width:50,align:'center',sortable:false},
	        {field:'update_time',title:'更新时间',width:50,align:'center',sortable:false}
	    ]],
	    pagination:true,
		rownumbers:true,
		toolbar:[{
			text:'添加设计模板',
			iconCls:'icon-ok',
			handler:function(){
				addDesignInfo();
			}
		},
		{
			text:'移除设计模板',
			iconCls:'icon-cancel',
			handler:function(){
				delDesignInfo();
			}
		}]
	    
	});
}

//添加设计模板
function addDesignInfo(){
	var type = $("#stType").val();
	$("#desBtn").show();
	$("#sDesignForm").form('clear');
	$('#sDesignDlg').window({
		title:'设计模板列表',
		iconCls:'icon-edit',
		modal: true,
		shadow: true,
		collapsible:false,
		minimizable:false,
		maximizable:false
	});
	if(type==3){
		$("#queryTmplType").combobox('disable');
		$("#queryTmplType2").combobox('disable');
		$("#queryTmplType3").combobox('disable');
	}else{
		var url=appPath+'/itbCom/selectOneType.action?type='+type;
		$.get(url,function(ret){
			var info = ret[0];
			var type_id =Number(info.type_id||0);
			var parent = Number(info.parent||0);
			var top_parent = Number(info.top_parent||0);
			var nParent = Number(parent);
			if(nParent>0 && nParent<10||nParent==1010||nParent==1011){
				parent = type_id;
			}
			// 大分类
			$("#queryTmplType").combobox({
				url:appPath+'/itbTg/getTypeForCombo.action?topIds=1,2,3,4,6,7,8,1010,1011&blkFlg=1',
				valueField:'type_id',
				textField:'type_name',
				onSelect:function(selRecd){
					$("#queryTmplType2").combobox("clear");
					$("#queryTmplType3").combobox("clear");
					$("#queryTmplType2").combobox("loadData",{});
					$("#queryTmplType3").combobox("loadData",{});
					// 中分类
					var parentId=selRecd.type_id;
					if(Number(parentId)>0){
						$("#queryTmplType2").combobox({
							url:appPath+'/itbTg/getTypeForCombo.action?parent='+parentId+'&blkFlg=1',
							valueField:'type_id',
							textField:'type_name',
							onSelect:function(selRecd2){
								$("#queryTmplType3").combobox("clear");
								$("#queryTmplType3").combobox("loadData",{});
								var parentId2=selRecd2.type_id;
								if(Number(parentId2)>0){
									$("#queryTmplType3").combobox({
										url:appPath+'/itbTg/getTypeForCombo.action?parent='+parentId2+'&blkFlg=1',
										valueField:'type_id',
										textField:'type_name'
									});
								}
							},
							onLoadSuccess:function(){
								if(parent){
									$("#queryTmplType2").combobox('disable');
								}
								$("#queryTmplType2").combobox('setValue',parent);
					            var val = $(this).combobox("getData");
					            for (var item in val[0]) {
					                if (item == "type_id") {
					                    $(this).combobox("select", parent);
					                }
					            }
							}
						});
					}
				},
				onLoadSuccess:function(){
					$("#queryTmplType").combobox('disable');
					$("#queryTmplType").combobox('setValue',top_parent);
		            var val = $(this).combobox("getData");
		            for (var item in val[0]) {
		                if (item == "type_id") {
		                    $(this).combobox("select", top_parent);
		                }
		            }
				}
			});
		});
	}
	$('#sDesignDlg').window('move',{top:0,left:20});
	$('#sDesignDlg').window('open');
	$("#queryVip").combobox({
		data:[{'id':"-1",'name':'不限'},{'id':"0",'name':'普通模板'},{'id':"10",'name':'VIP模版'}],
		valueField:'id',
		textField:'name',
		value:-1
	});
	initSuitDesign();
}
//移除设计模板
function delDesignInfo(){
	var selectItem=$("#tDesignGrid").datagrid("getChecked");
	var type = $("#stType").val();
	var stId = $("#st_id").val();
	if(!selectItem || selectItem.length == 0){
		$.messager.alert('提示信息','请选择一个设计模板！！','warning');
		return;
	}
	$.messager.confirm("确认","确认移除该设计模板？",function(r){
	        if (r) { 
				var ids = "";
				$.each(selectItem, function(index, item){
					ids= ids + item.design_id+",";
				});
				ids = ids.substring(0, ids.length-1);
				var url = appPath+"/itbCom/delTopicDesign.action?stId="+stId+"&design_id="+ids;
				$.post(url,function(data){
					if(data=="ok"){
						$.messager.alert('提示信息','移除成功','info');
						doQuery2();
					}else{
						$.messager.alert('提示信息','移除失败','info');
					}
				});
	        }
		}
	);
}

/**专题下设计模板顺序*/
function editTorder(designId, order){
	$("#orderDesignId").val(designId);
	$("#tOrder").val(order);
	$("#orderTBtn").show();
	$('#tOrderDlg').window({
		title:'专题下模板顺序',
		iconCls:'icon-edit',
		modal: true,
		shadow: true,
		collapsible:false,
		minimizable:false,
		maximizable:false
	});
	$('#tOrderDlg').window('move',{top:20,left:20});
	$('#tOrderDlg').window('open');
}

/**修改专题下设计模板顺序*/
function doUpdTOrder(){
	var designId = $("#orderDesignId").val();
	var order = $("#tOrder").val();
	var stId = $("#st_id").val();
	if(!order || order.length == 0 || Number(order)>999 || Number(order)<=0){
		$.messager.alert('提示信息','有效数值范围为：1～999','warning');
		return;
	}
	var url = appPath+"/itbCom/updTorder.action?designId="+designId+"&order="+order+"&stId="+stId;
	$.post(url,function(data){
		if(data=="ok"){
				$.messager.alert('提示信息','显示顺序已更新！','info',function(){
				doQuery2();
				$('#tOrderDlg').window('close');
			});
		}else {
			$.messager.alert('提示信息','显示顺序更新失败！','warning');
		}
	});
}

function cancelUpdTOrder(){
	$('#tOrderDlg').window('close');
}

function getTopTypeNm(value){
	var tn = '';
	switch(Number(value||'0')){
  	case 1: tn='单页';break;
  	case 2: tn='多页';break;
  	case 3: tn='PPT';break;
  	case 4: tn='<span style="color:red">印品</span>';break;
  	case 6: tn='社交媒体';break;
  	case 7: tn='电商';break;
  	case 8: tn='微商';break;
  	case 1010: tn='Logo商品';break;
  	case 1011: tn='营销商品';break;
  }
  return tn;
}

//适合的设计模板信息
function initSuitDesign(){
	var type = $("#stType").val();
	var stId = $("#st_id").val();
	$('#sDesignGrid').datagrid({
	    url:appPath + "/itbCom/getSuitDesignInfo.action?type="+type+"&stId="+stId,
	    height:'full',
	    striped:true,
	    fitColumns:true,
	    nowrap: false,// 换行
	    queryParams: getQueryParam3(),
	    singleSelect:false,
	    selectOnCheck:true,
	    checkOnSelect:true,
	    frozenColumns:[[
	        {field:'ck',checkbox:'true',width:10,align:'center',sortable:false}
	    ]],
	    columns:[[
  	        {field:'st_id',title:'添加状态',width:35,align:'left',sortable:false,
	        	formatter:function(value,rowData,rowIndex){
	        		if(value){
	        			return '<span style="color:red">已添加</span>';
	        		}
	        		return '<span style="color:green;">未添加</span>';
	        	}
	        },
  	        {field:'thumb',title:'缩略图',width:60,align:'center',sortable:false,
	        	formatter:function(thumb, rowData, rowIndex){
	        		var retUrl = '';
	        		if (rowData.thumb) {
	        			retUrl = '<a href="' + rowData.thumb + '" target="_blank">'
	        				+ '<div style="display:table;text-align:center;height:95px;width:95px;">'
	        				+ '<span style="display:table-cell;vertical-align:middle">'
	        				+ '<img src="'+thumb+'?x-oss-process=image/resize,m_lfit,h_100,w_100'
	        				+ '" style="display:inline;max-height:95px;max-width:95px"></span></div></a>';
	        		}
	        		return retUrl;
	        	}
  	        },
	        {field:'design_id',title:'模版ID',width:35,align:'center',sortable:false,
		    	formatter:function(id, rowData, rowIndex){
		    		var show = '<span style="color:blue;">'+id+'</span>';
		    		if(rowData.map_id){
		    			show = '<span style="color:blue;">'+id+'</span>'+
		    			'</br>'+
		    			'<span style="color:green;">'+rowData.map_id+'</span>';
		    		}
		    		return show;
		    	}
		    },
	        {field:'size',title:'尺寸(W*H)',width:55,align:'center',sortable:false,
		    	formatter:function(value, rowData, rowIndex){
		    		return ''+(rowData.width||'N/A')+
		    			'<span style="color:green">*</span>'+
		    			(rowData.height||'N/A')+'';
		    	}
		    },
		    {field:'top_type',title:'主分类',width:35,align:'center',sortable:false,
		    	formatter:function(value, rowData, rowIndex){
		    		var tn = getTopTypeNm(value);
		    		if(!tn || tn.length==0) {
		    			tn = '<span style="color:red">未知</span>';
		    		}
		    		return tn;
		    	}
		    },
	        {field:'editType',title:'子分类',width:40,align:'center',sortable:false,
		    	formatter:function(value, rowData, rowIndex){
		    		return rowData.type_name || '<span style="color:red">未分类</span>';
		    	}
		    },
		    {field:'user_id',title:'设计师',width:50,align:'center',sortable:false,
		    	formatter:function(value, rowData, rowIndex){
		    		return rowData.nickname || rowData.user_name || rowData.user_id || '<span style="color:red">未知</span>';
		    	}
		    },
		    {field:'item_id',title:'关联商品',width:40,align:'center',sortable:false,
		    	formatter:function(value, rowData, rowIndex){
		    		var topType = Number(rowData.top_type||'0');
		    		if(topType!=4 && topType!=1010 && topType!=1011) {
		    			return '<span style="color:#FF3030;">N/A</span>';
		    		}
		    		if(Number(value||'0')==0) {
		    			return '<span style="color:blue">未关联</span>';
		    		}
		    		return value;
		    	}
		    },
	        {field:'design_name',title:'模版名称',width:70,align:'left',sortable:false},
		    {field:'vip',title:'VIP',width:35,align:'center',sortable:false,
		    	  formatter:function(value, rowData, rowIndex){
		    		  var show = "<span style='color:green;'>普通模板</span>";
		    		  if(Number(value||'0')==10) show="<span style='color:red;'>VIP模版</span>";
		    		  return show;
		    	  }
		    },
	        {field:'publish',title:'发布状态',width:40,align:'center',sortable:false,
	        	formatter:function(publish, rowData, rowIndex){
	        		if (Number(publish) == 1) return '<span style="color:green">已发布</span>';
	        		return '<span style="color:red">未发布</span>';
	        	}
		    },
	        {field:'create_time',title:'创建时间',width:50,align:'center',sortable:false},
	        {field:'update_time',title:'更新时间',width:50,align:'center',sortable:false}
	    ]],
	    pagination:true,
		rownumbers:true
	});
}

//添加设计模板到专题下
function addToSpecial(){
	var checkRows = $("#sDesignGrid").datagrid('getChecked');
	var type = $("#stType").val();
	var stId = $("#st_id").val();
	if(checkRows.length==0){
		$.messager.alert('提示信息','请选择设计作品！','info');
		return;
	}else{
		var ids =[];
		var info = [];
		for(var i=0;i<checkRows.length;i++){
			var st = Number(checkRows[i].st_id);//根据是否st_id>0  判断是否已经添加过模板
			if(st<=0){
				var sts = {"design_id":checkRows[i].design_id,"top_type":checkRows[i].top_type};
				ids.push(sts);
			}else{
				info.push(checkRows[i].design_id);
			}
		}
		if(info.length>0){
			$.messager.alert('提示信息','勾选的有已经添加过的模板设计！','info');
			return;
		}
		$.messager.confirm("确认","确定将该设计作品添加到该专题下？？",function(r){
	        if (r) { 
	        	var designIds = JSON.stringify(ids)
				var url = appPath+"/itbCom/addSuitDesign.action";
				var data = {"stId":stId,"design_id":designIds};
				$.post(url,data,function(data){
					if(data=="ok"){
						$.messager.alert('提示信息','添加成功！','info');
						doQuery2();
						doQuery3();
					}else if(data=="exit"){
						$.messager.alert('提示信息','该专题下已经存在该设计模板！！','info');
					}else if(data=="no"){
						$.messager.alert('提示信息','添加失败','info');
					}
				});
	        }
		});
	}
}

/**获取请求信息*/
function getQueryParam3(){
	var queryObject = {};
	var findTmplType =$("#queryTmplType3").combobox('getValue');
	if(!findTmplType){
		findTmplType =$("#queryTmplType2").combobox('getValue');
		if(!findTmplType){
			findTmplType=$("#queryTmplType").combobox('getValue');
		}
	}
	if (Number(findTmplType)>0) {
		queryObject.findTmplType = findTmplType;// 类型
	}
	var findVip = $("#queryVip").combobox('getValue');
	var findTmplName=$("#queryTmplName").val();
	var findTmplId=$("#queryTmplId").val();
	var findItemId=$("#queryItemId").val();
	if(findVip&&findVip.length>0&&Number(findVip)>=0) queryObject.findVip = findVip;// vip
	if(findTmplName&&findTmplName.length>0) queryObject.findTmplName = findTmplName;// 模版名称
	if(findTmplId&&findTmplId.length>0) queryObject.findTmplId = findTmplId;// 模版id
	if(findItemId&&findItemId.length>0) queryObject.findItemId = findItemId;// 商品id
	return queryObject;
}

/**查询数据*/
function doQuery3(startFlg){
	$("#sDesignGrid").datagrid('unselectAll');
	if(startFlg == 1) {
		$("#sDesignGrid").datagrid('load', getQueryParam3());
	} else {
		$("#sDesignGrid").datagrid('reload', getQueryParam3());
	}
}


//******************************** 上传图片 *******************************
var myDomain = 'http://7xogoq.com1.z0.glb.clouddn.com';
var ossDmain = "http://itbour-back.oss-cn-hangzhou.aliyuncs.com/";
var validFile = false;
var uploader = null;

// 图像缩放
function DrawImage(ImgD,FitWidth,FitHeight){
    var image=new Image();
    image.src=ImgD.src;
    if(image.width>0 && image.height>0){
        if(image.width/image.height>= FitWidth/FitHeight){
            if(image.width>FitWidth){
                ImgD.width=FitWidth;
                ImgD.height=(image.height*FitWidth)/image.width;
            }else{
                ImgD.width=image.width; 
               ImgD.height=image.height;
            }
        } else{
            if(image.height>FitHeight){
                ImgD.height=FitHeight;
                ImgD.width=(image.width*FitHeight)/image.height;
            }else{
                ImgD.width=image.width; 
               ImgD.height=image.height;
            } 
       }
    }
}

function isImage(url) {
    var res, suffix = "";
    var imageSuffixes = ["png", "jpg", "jpeg", "gif", "bmp"];
    var suffixMatch = /\.([a-zA-Z0-9]+)(\?|\@|$)/;

    if (!url || !suffixMatch.test(url)) {
        return false;
    }
    res = suffixMatch.exec(url);
    suffix = res[1].toLowerCase();
    for (var i = 0, l = imageSuffixes.length; i < l; i++) {
        if (suffix === imageSuffixes[i]) {
            return true;
        }
    }
    return false;
}

function doPostData(){// 开始上传
	if (validFile && uploader) {
		uploader.start();
	} else {
		setMsg("red", "请选择图像文件！");
	}
}

function cancelPostData(){ // 取消上传
	if (uploader) {
		uploader.destroy();
		uploader = null;
	}
}

function setMsg(color, msg) {
	$.messager.alert('提示信息',msg,'info');
}

function fmtCreateTime(value, rowData, rowIndex){
	if(!value)return "";
	var s = new Date(value);
	return rowData.create_time=$.DateUtil.format(s,'yyyy/MM/dd hh:mm:ss');
}

function fmtHotFlag(value, rowData, rowIndex){
	if(rowData.hotFlag==1)return "是";
	return "否";
}





// ############### FOR OSS UPLOAD START ###############
//var accessid= '';
//var accesskey= '';
//var uploadHost = 'http://itbour-back.oss-cn-hangzhou.aliyuncs.com';
var g_object_name = '';
var dtNow = Date.parse(new Date()); //Date.parse(new Date())/1000;
//var policyText = {
//"expiration": "2020-01-01T12:00:00.000Z", //设置该Policy的失效时间，超过这个失效时间之后，就没有办法通过这个policy上传文件了
//"conditions": [
//  ["content-length-range", 0, 104857600] // 设置上传文件的大小限制
//]
//};
//var policyJsonStr = JSON.stringify(policyText);
//var policyBase64 = Base64.encode(policyJsonStr);
//var message = policyBase64;
//var bytes = Crypto.HMAC(Crypto.SHA1, message, accesskey, { asBytes: true });
//var signature = Crypto.util.bytesToBase64(bytes);

var OSS_PARAM = {
	expire: 0,
	uploadHost: '',
	accessKeyId: '',
	policyBase64: '',
	signature: '',
	flg: false
};

function randomString(len) {
	len = len || 20;
	var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';   
	var maxLen = chars.length;
	var str = '';
	for (var i = 0; i < len; i++) {
		str += chars.charAt(Math.floor(Math.random() * maxLen));
    }
	return str;
}

function getSuffix(filename) {
    var pos = filename.lastIndexOf('.');
    var suffix = '';
    if (pos != -1) {
        suffix = filename.substring(pos);
    }
    return suffix;
}

function calculate_object_name(filename) {
	if (g_object_name){
		g_object_name = '';
	}
	var now = new Date(); 
	var nowStr = now.format("yyyy/MM/dd/hhmmssS_");
    g_object_name = "image/U"+g_userId+"/"+nowStr + randomString(20);
}

function set_upload_param(up, filename, ret) {
	// 判断当前expire是否超过了当前时间,如果超过了则重新取
	dtNow = Date.parse(new Date());//  Date.parse(new Date())/1000
	OSS_PARAM.flg = false;
    if (OSS_PARAM.expire < dtNow + 5000) {// 5s
    	var url = appPath+"/itbImg/getOSSToken.action";
        $.get(url, function(data){  
    		if (data && data.signature) { 
    			OSS_PARAM.expire = data.expire;
    			OSS_PARAM.uploadHost = data.uploadHost;
    			OSS_PARAM.accessKeyId = data.accessKeyId;
    			OSS_PARAM.policyBase64 = data.policyBase64;
    			OSS_PARAM.signature = data.signature;
    			OSS_PARAM.flg = true;
    			
    			doUpStart(up, filename, ret);
            } else {
            	$.messager.alert('提示信息','上传异常, 请重新尝试!','info');
            }  
        });
    } else {
    	doUpStart(up, filename, ret);
    }
}

function doUpStart(up, filename, ret){
	if (filename && filename != '') {
        calculate_object_name(filename);
    }
    var new_multipart_params = {
        'key' : g_object_name,
        'policy': OSS_PARAM.policyBase64,
        'OSSAccessKeyId': OSS_PARAM.accessKeyId, 
        'success_action_status' : '200', //让服务端返回200,不然，默认会返回204
        'signature': OSS_PARAM.signature,
    };

    up.setOption({
        'url': OSS_PARAM.uploadHost,
        'multipart_params': new_multipart_params
    });

    up.start();
}

function clearUploadList() {
	$("#topicImg").html('');
	$("#topicImg").val('');
}

function initOSS() {
	if (uploader) {
		uploader.destroy();
		uploader = null;
	}

	uploader = new plupload.Uploader({
		runtimes : 'html5,flash,silverlight,html4',
		browse_button : 'selImgFile', 
	    //multi_selection: false,
		//container: document.getElementById('container'),
		//flash_swf_url : 'lib/plupload-2.1.2/js/Moxie.swf',
		//silverlight_xap_url : 'lib/plupload-2.1.2/js/Moxie.xap',
	    url : 'http://oss.aliyuncs.com',
		init: {
			PostInit: function() {// 当Init事件发生后触发
//				document.getElementById('upImgFile').onclick = function() {
//		            set_upload_param(uploader, '', false);
//		            return false;
//				};
			},

			FilesAdded: function(up, files) {
				clearUploadList();
				$('#uploadMsg').hide();
				
				var delLen = (up.files.length>=files.length)?(up.files.length-files.length):up.files.length;
				up.splice(0,delLen);
				
				var bAllOk = true;
				plupload.each(files, function(file) {
					if (isImage(file.name)) {
						// add file info list
						set_upload_param(uploader, '', false);
				        return false;
					} else {
						bAllOk = false;
						var ngFile = up.getFile(file.id);
						if (ngFile) {
							up.removeFile(ngFile);
						}
					}
				});
				
				if (!bAllOk) {
					setMsg("red", "已过滤非图像文件！");
				}     
			},

			BeforeUpload: function(up, file) {
	            set_upload_param(up, file.name, true);
	        },

			UploadProgress: function(up, file) {
//				var d = document.getElementById(file.id);
//				d.getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";
//	            var prog = d.getElementsByTagName('div')[0];
//				var progBar = prog.getElementsByTagName('div')[0];
//				progBar.style.width= 2*file.percent+'px';
//				progBar.setAttribute('aria-valuenow', file.percent);
//				setMsg("green", file.name + ' 上传中...');
			},

			FileUploaded: function(up, file, info) {
	            if (info.status == 200) {
	            	console.log(g_object_name);
	            	var showImg = '';
	            	var tmp = ossDmain+g_object_name
	    			if(g_object_name && g_object_name.length>0) {
	    				showImg = tmp.replace('oss-cn-hangzhou.aliyuncs.com','img-cn-hangzhou.aliyuncs.com')
	    					+'@200h_200w_1l.png';
	    			}
	    			var imgHtml = '<img src="'+showImg+'" style="display:inline;max-height:100px;max-width:200px">';
	    			$("#topicImg").append(imgHtml).val(tmp||'');
	            } else {
	            	setMsg("red", '上传出错！');
	            }
			},

			Error: function(up, err) {
//				document.getElementById('console').appendChild(document.createTextNode("\nError xml:" + err.response));
				setMsg("red", err.response);
			}
		}
	});
	
	uploader.init();
}
//############### FOR OSS UPLOAD END ###############